package com.ruibang.glass.produce.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruibang.glass.produce.domain.req.DeviceAlarmReq;
import com.ruibang.glass.produce.entity.DeviceAlarm;
import com.ruibang.glass.produce.mapper.DeviceAlarmServiceMapper;
import com.ruibang.glass.produce.service.DeviceAlarmService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.ZoneOffset;


/**
 * @Author: songJinKang
 * @CreateTime: 2024-05-04  19:55
 * @Description: TODO:生产设备报警数据
 * @Version: 1.0
 */

@Slf4j
@Service
public class DeviceAlarmServiceImpl extends ServiceImpl<DeviceAlarmServiceMapper, DeviceAlarm> implements DeviceAlarmService {


    @Override
    public IPage<DeviceAlarm> pageQuery(DeviceAlarmReq deviceAlarmReq) {
        //报警开始时间
        if (deviceAlarmReq.getAlarmBeginStartTime() != null && deviceAlarmReq.getAlarmBeginEndTime() != null) {
            long end = deviceAlarmReq.getAlarmBeginEndTime().toInstant(ZoneOffset.of("+8")).toEpochMilli();
            long start = deviceAlarmReq.getAlarmBeginStartTime().toInstant(ZoneOffset.of("+8")).toEpochMilli();
            deviceAlarmReq.setAlarmBeginStartTs(start);
            deviceAlarmReq.setAlarmBeginEndTs(end);
        }
        //报警结束时间
        if (deviceAlarmReq.getAlarmEndTime() != null && deviceAlarmReq.getAlarmEndStartTime() != null) {
            long end = deviceAlarmReq.getAlarmEndTime().toInstant(ZoneOffset.of("+8")).toEpochMilli();
            long start = deviceAlarmReq.getAlarmEndStartTime().toInstant(ZoneOffset.of("+8")).toEpochMilli();
            deviceAlarmReq.setAlarmEndStartTs(start);
            deviceAlarmReq.setAlarmEndTs(end);
        }
        return baseMapper.pageQuery(new Page<>(deviceAlarmReq.getPageNo(), deviceAlarmReq.getPageSize()), deviceAlarmReq);
    }

}
